package icursoft.educationms.http;


import java.util.concurrent.TimeUnit;

import icursoft.educationms.interf.RetrofitImpl;
import icursoft.educationms.util.MachTalkUtil;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by Administrator on 2016/10/26.
 */

public class RetrofitClient {

    private RetrofitImpl apiService;

    private static RetrofitClient sNewInstance;

    public static RetrofitClient getInstance() {

        if (sNewInstance == null) {
            sNewInstance = new RetrofitClient();
        }
        return sNewInstance;
    }

    private RetrofitClient() {

        OkHttpClient okHttpClient = new OkHttpClient.Builder().addInterceptor
                (new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
                .connectTimeout(10000, TimeUnit.SECONDS).readTimeout(10000, TimeUnit.SECONDS).build();

        Retrofit retrofit = new Retrofit.Builder()
                .client(okHttpClient)
                .addConverterFactory(GsonConverterFactory.create())
                .baseUrl(MachTalkUtil.BASE_URL)
                .build();

        apiService = retrofit.create(RetrofitImpl.class);
    }

    public RetrofitImpl getApiService() {
        return this.apiService;
    }

}
